package cn.elwin.samples;

import android.os.Bundle;
import android.provider.Contacts.Intents;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

/* ListView有两种用法：一种是继承ListActivity类，另一种是和一般控件的用法类似
 * 这里展示的是第一种用法——继承ListActivity类，这种用法的优点是什么暂且还不知道，但缺点是一个Activity中最多只能有一个ListView */

public class Composite extends ListActivity {

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);

		Intent intent = new Intent();
		switch (position) {
		case 0:
			intent.setClass(this, TwoListView.class);
			break;
		default:
			break;
		}
		this.startActivity(intent);
	}

	private static final String[] list = { "控件式ListView", "ExpandAbleListView",
			"GridView", "ScrollView", "HorizontalScrollView", "SearchView",
			"SlidingDrawer", "TableHost", "WebView" };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_composite); // 一个继承自ListActivity的类，可以没有setContentView()。不写setContentView()相当于布局文件只有一个默认的ListView控件
		setListAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, list));
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.composite, menu);
		return true;
	}

}
